<?php
class Model extends connect_db{
public $select;
public $where;
public $order;
public $limit;

public function __construct(){
	$this->connect();
}

public function __destruct(){
	$this->disconnect();
}

public function insert($table,$data){
	$key=array_keys($data);
	$col=implode(",",$key);
	$value=array_values($data);
	foreach($value as $item){
		$arr[]="'$item'";
	}
	$val=implode(",",$arr);
	$sql= "insert into $table($col) values($val)";
	$this->query($sql);
}	

public function update($table,$data){
	foreach($data as $k=>$v){
		$arr[]="$k='$v'";
	}
	$str=implode(",",$arr);
	if($this->where != ""){
		$where="where ".$this->where;
	}
	
	$sql= "update $table set $str $where";
	$this->query($sql);
}

public function delete($table){
	if($this->where != ""){
		$where="where ".$this->where;
	}
	$sql="delete from $table $where";
	$this->query($sql);
}

public function select($str){
	$this->select=$str;
}

public function where($where){
	if(is_array($where)){
		foreach($where as $k=>$v){
			$arr[]="$k $v";
		}
		$this->where=implode(" and ",$arr);
	}else{
		$this->where=$where;
	}
}

public function order($str){
	$this->order=$str;
}

public function limit($str){
	$this->limit=$str;
}

public function getdata($table){
	if($this->select != ""){
		$select=$this->select;
	}else{
		$select="*";
	}
	if($this->where != ""){
		$where="where ".$this->where;
	}
	if($this->order != ""){
		$order="order by ".$this->order;
	}
	if($this->limit != ""){
		$limit="limit ".$this->limit;
	}
	$sql= "select $select from $table $where $order $limit";
	$this->query($sql);
}

}